package com.ruoyi.web.controller.community.electronicCommerce;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.EcAddress;
import com.ruoyi.community.service.ec.IEcAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区电商Controller
 * 
 * @author ruoyi
 * @date 2021-08-15
 */
@RestController
@RequestMapping("/e-commerce/address")
public class EcAddressController extends BaseController
{
    @Autowired
    private IEcAddressService ecAddressService;

    /**
     * 查询社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(EcAddress ecAddress)
    {
        startPage();
        List<EcAddress> list = ecAddressService.selectEcAddressList(ecAddress);
        return getDataTable(list);
    }

    /**
     * 导出社区电商列表
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:export')")
    @Log(title = "社区电商", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EcAddress ecAddress)
    {
        List<EcAddress> list = ecAddressService.selectEcAddressList(ecAddress);
        ExcelUtil<EcAddress> util = new ExcelUtil<EcAddress>(EcAddress.class);
        return util.exportExcel(list, "社区电商数据");
    }

    /**
     * 获取社区电商详细信息
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:query')")
    @GetMapping(value = "/{addressId}")
    public AjaxResult getInfo(@PathVariable("addressId") Integer addressId)
    {
        return AjaxResult.success(ecAddressService.selectEcAddressById(addressId));
    }

    /**
     * 新增社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:add')")
    @Log(title = "社区电商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EcAddress ecAddress)
    {
        return toAjax(ecAddressService.insertEcAddress(ecAddress));
    }

    /**
     * 修改社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:edit')")
    @Log(title = "社区电商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EcAddress ecAddress)
    {
        return toAjax(ecAddressService.updateEcAddress(ecAddress));
    }

    /**
     * 删除社区电商
     */
    @PreAuthorize("@ss.hasPermi('e-commerce:address:remove')")
    @Log(title = "社区电商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{addressIds}")
    public AjaxResult remove(@PathVariable Integer[] addressIds)
    {
        return toAjax(ecAddressService.deleteEcAddressByIds(addressIds));
    }
}
